﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Dcms.Common;
using Dcms.BLL;
using Dcms.Model;

public partial class voteform : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string selectText = DcmsRequest.GetFormString("selectText");
        string errorMessage = DcmsRequest.GetFormString("ErrorMessage");
        string successMessage = DcmsRequest.GetFormString("SuccessMessage");
        string backUrl = DcmsRequest.GetFormString("BackUrl");
        string[] selectTextArr = selectText.Split('|');
        int selectTextArrLen = selectTextArr.Length;
        int voteId = DcmsRequest.GetFormInt("VoteID", 0);
        if (voteId > 0)
        {
            Dcms_VoteModel vModel = new Dcms_VoteModel();
            Dcms_VoteBLL vBll = new Dcms_VoteBLL();
            vModel = vBll.GetModelByID(voteId);
            string[] ValueArr=vModel.Vote_Value.Split('|');
            string ValueString = string.Empty;
            for (int i = 0; i < vModel.Vote_ItemNum; i++)
            {
                for (int a = 0; a < selectTextArrLen; a++)
                {
                    if (i == Utils.StrToInt(selectTextArr[a], 0))
                    {
                        int ValueStr = Utils.StrToInt(ValueArr[i], 0) + 1;
                        ValueArr[i] = ValueStr.ToString();
                    }
                }
                if (i == 0)
                {
                    ValueString = ValueString + ValueArr[i];
                }
                else
                {
                    ValueString = ValueString + "|" + ValueArr[i];
                }
            }
            vModel.Vote_Value = ValueString;
            vBll.Update(vModel);
        }
        Jscript.AlertAndRedirect(successMessage, backUrl);
    }
}
